package com.xbq.exceleditor.adapter

import com.blankj.utilcode.util.PathUtils
import com.blankj.utilcode.util.ResourceUtils
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xbq.exceleditor.R
import com.xbq.exceleditor.databinding.ItemHomeTemplateBinding
import java.io.File
import javax.inject.Inject

/**
 * Author: liaohaiping
 * Time: 2021-01-20
 * Description:
 */

class TemplateAdapter @Inject constructor():
    BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_home_template) {
    override fun convert(holder: BaseViewHolder, item: String) {
        ItemHomeTemplateBinding.bind(holder.itemView).let {
            var destFile = File(PathUtils.getExternalAppCachePath(),item)
            if (!destFile.exists()) {
                ResourceUtils.copyFileFromAssets("templates/${item}", destFile.absolutePath)
            }
            Glide.with(it.templateImage)
                .load(destFile)
                .into(it.templateImage)
            it.tempateTitle.text = destFile.nameWithoutExtension
        }
    }
}